#include "config_main.h"
#ifdef DDENN_COMMANDS
/*
 * commands.h
 *
 *  Created on: 06.06.2009
 *      Author: Admin
 */

#include "commands.h"


/**************************************************************************************/
//
//        it provides enable/disable commands
//
/*************************************************************************************/


int DdennCommands::DdennCommandsDisableDummyFunction(
                                   XPLMCommandRef       inCommand,
                                   XPLMCommandPhase     inPhase,
                                   void *               inRefcon){return 0;}


void DdennCommands::DdennCommandsDisable(){
	FILE *F;
	char buf[255]="";
	if (F = fopen(
			getFileNameinPluginDir("commands.cfg")
			,"r")){
		for (int i=0;
			(fgets(buf,255,F)!=NULL);
			i++){
			char namecomm[255];
			char option[255];
			sscanf(buf,"%s%s",namecomm,option);
			if (!strcmp (option,"disable")){
				  XPLMRegisterCommandHandler(XPLMFindCommand(namecomm),DdennCommandsDisableDummyFunction,1,NULL);
			}
		}
		fclose(F);
	}
}


void DdennCommands::DdennCommandsEnable(){
	FILE *F;
	char buf[255]="";
	if (F = fopen(
			getFileNameinPluginDir("commands.cfg")
			,"r")){
		for (int i=0;
			(fgets(buf,255,F)!=NULL);
			i++){
			char namecomm[255];
			char option[255];
			sscanf(buf,"%s%s",namecomm,option);
			if (!strcmp (option,"disable")){
				  XPLMUnregisterCommandHandler(XPLMFindCommand(namecomm),DdennCommandsDisableDummyFunction,1,NULL);
			}
		}
		fclose(F);
	}
}


/**************************************************************************************/
//
//        end of enable/disable commands
//
/*************************************************************************************/

#endif
